// 所有模块都通过 define 来定义
define(function(require, exports, module) {
	require('jquery');
	var ws = require('Socket');
	var template=require("template");
	var tempCon = $("#templateCon");
	var callback = null;
	module.exports = {
		listNamespace : listNamespace,
		render:render
	};
	ws.addListener('listByNamespace', function(data) {
		$.each(data, function(i, v) {
			var idVal = v.id.namespace + "#" + v.id.tagName;
			var id = "[id='" + idVal + "']";
			if ($(id).length == 0) {
				var temp = "<script id='" + idVal + "' type='text/html'>"
						+ v.template + "</script>";
				tempCon.append(temp);
			}
		});
		if (callback) {
			callback(data);
			callback = null;
		}
	});
	function listNamespace(space, tempcallback) {
		ws.send('template', 'listByNamespace', space);
		callback = tempcallback;
	}
	function render(pro){
		var idVal = pro.namespace + "#" + pro.tagName;
		var result=template(idVal, pro);
		return result;
	}
});